package com.wad.controller;

import com.wad.common.ResponseResult;
import com.wad.domain.User;
import com.wad.security.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;


/**
 * @author wad
 * @date 2022/11/11 10:02
 * @project JWT_DEMO2
 **/
@RestController
@Slf4j
public class LoginController {


    @Autowired
    private LoginService loginService;


    /**
     * 登录接口
     * @param user
     * @return
     * @throws UnsupportedEncodingException
     */
    @PostMapping("/user/login")
    public ResponseResult login(@RequestBody User user) throws Exception {
        return loginService.login(user);
    }


    /**
     * 退出登录
     * @return
     */
    @GetMapping("/user/logout")
    public ResponseResult logout(){
        return loginService.logout();
    }


    /**
     * 注册接口
     * @param user
     * @return
     */
    @PostMapping("/user/register")
    public ResponseResult register(@RequestBody User user){
        return loginService.register(user);
    }
}
